﻿package Modules.PlayerModule.InventoryModule
{
	import Modules.PlayerModule.InventoryModule.Tables.*;
	
	public class Inventory
	{
		public var itemTable:ItemTable;
		public var loadedItemArray:Array;
		
		//constructor
		public function Inventory()
		{
			initInventory();
		}
		
		public function initInventory():void{
			
			//create an empty and load inventory with all the items at quantity = 0
			itemTable = new ItemTable();
			itemTable.loadTable();
		}
		
		//function for mass updates of inventory during loading
		public function loadInventory(loadedArray:Array):void{
			
			loadedItemArray = loadedArray;
			
			var length:int = loadedItemArray.length;
			var i:int;
			
			for(i=0; i<length; i++){
				
				updateInventoryItem(loadedItemArray[i]);			
			}
			
			//itemTable.printTable();
		}
		
		//return the entire  item table upon call
		public function getInventoryTables():ItemTable{
			
			return itemTable;
		}
		
		//update an object to the specified quantity
		private function updateInventoryItem(object:Object):void{
			
			itemTable.setItemAmount(object.id, object.amount);			
		}
		
		public function save():Array{
			
			var storageArray = itemTable.saveStorage();;
			
			return storageArray;
		}
	}
}	